package easeui.widget.chatrow;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.activity.BrowseActivityHx;
import com.github.postsanf.yinian.bean.YNHistory;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.nostra13.universalimageloader.core.ImageLoader;

public class EaseChatRowHistoryImage2 extends EaseChatRowHistoryFile2 {
    protected ImageView imageView;
    private int direction;
    private String url;
    private String thumburi;


    public EaseChatRowHistoryImage2(Context context, YNHistory message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
    }

    @Override
    protected void onInflateView() {
        direction = message.getFrom().equals(String.valueOf(application.getCurID())) ? 0 : 1;
        inflater.inflate(direction == 1 ? R.layout.ease_row_received_picture2 : R.layout.ease_row_sent_picture2, this);
    }

    @Override
    protected void onFindViewById() {
        percentageView = (TextView) findViewById(R.id.percentage);
        imageView = (ImageView) findViewById(R.id.image);
    }


    @Override
    protected void onSetUpView() {
        String thumbPath = message.getPayload().getBodies().get(0).getThumb();
        url = message.getPayload().getBodies().get(0).getUrl();
        thumburi = thumbPath.substring(0, thumbPath.lastIndexOf("/") + 1) + "160";
        progressBar.setVisibility(View.GONE);
        percentageView.setVisibility(View.GONE);
//        imageView.setImageResource(R.drawable.ease_default_image);
//                showImageView(thumbPath, imageView, imgBody.getLocalUrl(), message);
//        ImageOptHelper.showFrescoHxImg(Uri.parse(thumbPath), imageView, context);
        ImageLoader.getInstance().displayImage(thumburi, imageView);
    }

    @Override
    protected void onUpdateView() {
        super.onUpdateView();
    }

    @Override
    protected void onBubbleClick() {
        Intent intent = new Intent(context, BrowseActivityHx.class);
        intent.putExtra("singleurl", url);
        intent.putExtra(CommonConstants.YNPOSITION, 0);
//        Intent intent = new Intent(context, EaseShowBigImageActivity.class);
//        File file = new File(imgBody.getLocalUrl());
//        if (file.exists()) {
//            Uri uri = Uri.fromFile(file);
//            intent.putExtra("uri", uri);
//        } else {
//            // The local full size pic does not exist yet.
//            // ShowBigImage needs to download it from the server
//            // first
//            intent.putExtra("secret", imgBody.getSecret());
//            intent.putExtra("remotepath", imgBody.getRemoteUrl());
//            intent.putExtra("localUrl", imgBody.getLocalUrl());
//        }
//        if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked()
//                && message.getChatType() == ChatType.Chat) {
//            try {
//                EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
        context.startActivity(intent);
    }


}
